package com.redis.publish;

import redis.clients.jedis.Jedis;

/**
 * 发布类, 同时启动2个订阅客户端
 */
public class RedisPublish {
	public static void main(String[] args) {
		String cctv = "cctv";
		String ximalaya = "xi ma la ya";
		Jedis jedis = new Jedis("127.0.0.1", 6379);
		
		SubscribeThread lisi = new SubscribeThread("lisi", new String[] {cctv});
		lisi.start();
		SubscribeThread zhangsan = new SubscribeThread("zhangsan", new String[] {cctv, ximalaya});
		zhangsan.start();
		
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		jedis.publish(cctv, "美国大地震");
		jedis.publish(ximalaya, "贞观长歌");
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		zhangsan.unsubscribe(new String[] {cctv, ximalaya});
		jedis.publish(cctv, "日本大地震");
		lisi.unsubscribe(new String[] {cctv});
		
		jedis.close();
	}
}
